package net.lab1024.smartadmin.module.weapp.visitor;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.google.zxing.WriterException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.lab1024.smartadmin.common.anno.NoValidPrivilege;
import net.lab1024.smartadmin.common.controller.BaseController;
import net.lab1024.smartadmin.common.domain.PageResultDTO;
import net.lab1024.smartadmin.common.domain.ResponseDTO;
import net.lab1024.smartadmin.common.domain.ValidateList;
import net.lab1024.smartadmin.constant.SwaggerTagConst;
import net.lab1024.smartadmin.module.weapp.orders.domain.dto.*;
import net.lab1024.smartadmin.module.weapp.orders.domain.vo.OrdersExcelVO;
import net.lab1024.smartadmin.module.weapp.orders.domain.vo.OrdersPageBaseVO;
import net.lab1024.smartadmin.module.weapp.orders.domain.vo.OrdersVO;
import net.lab1024.smartadmin.module.weapp.orders.service.OrdersService;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * [  ]
 *
 * @author wuqian
 * @version 1.0
 * @company 五千
 * @copyright (c)  五千Inc. All rights reserved.
 * @date 2021-03-10 15:12:30
 * @since JDK1.8
 */
@RestController
@Api(tags = {SwaggerTagConst.Weapp.MANAGER_WORK_ORDER})
public class VisitorController extends BaseController {

    @Autowired
    private VisitorService visitorService;

    @ApiOperation(value = "分页查询",notes = "@author wuqian")
    @PostMapping("/visitor/page/query")
    @NoValidPrivilege
    public ResponseDTO<PageResultDTO<VisitorVO>> queryByPage(@RequestBody VisitorQueryDTO queryDTO) {
        return visitorService.queryByPage(queryDTO);
    }

//    @ApiOperation(value = "点赞",notes = "@author wuqian")
//    @PostMapping("orders/like_{id}")
//    @NoValidPrivilege
//    public ResponseDTO<String> upLike(@PathVariable Long id){
//        return visitorService.upLike(id);
//    }

    @ApiOperation(value = "添加",notes = "@author wuqian")
    @PostMapping("/visitor/add")
    @NoValidPrivilege
    public ResponseDTO<Long> add(@RequestBody @Validated VisitorAddDTO addTO) throws IOException {
        if(addTO.getId() != null && addTO.getId() > 0){
            return visitorService.update(addTO);
        }
        return visitorService.add(addTO);
    }

    @ApiOperation(value="审核",notes = "@author wuqian")
    @PostMapping("/visitor/handle")
    @NoValidPrivilege
    public ResponseDTO<String> handle(@RequestBody @Validated VisitorHandleDTO handDTO){
        return visitorService.hand(handDTO);
    }

//    @ApiOperation(value="切换一级管理员",notes = "@author wuqian")
//    @PostMapping("/orders/changeOrderPeroperHand")
//    @NoValidPrivilege
//    public ResponseDTO<String> changeOrderPeroperHand(@RequestBody @Validated OrdersHandleDTO handDTO){
//        return visitorService.changeOrderPeroperHand(handDTO);
//    }

    @ApiOperation(value = "详情", notes = "@author wuqian")
    @GetMapping("/visitor/detail/{id}")
    @NoValidPrivilege
    public ResponseDTO<VisitorVO> detail(@PathVariable("id") Long id) {
        return visitorService.getById(id);
    }
    @ApiOperation(value = "生成二维码", notes = "@author wuqian")
    @GetMapping("/visitor/getshareqr/{id}")
    @NoValidPrivilege
    public ResponseDTO<String> getshareqr(@PathVariable("id") Long id) throws IOException, WriterException {
        return visitorService.getshareqr(id);
    }


//    @ApiOperation(value="批量删除",notes = "@author wuqian")
//    @PostMapping("/orders/deleteByIds")
//    @NoValidPrivilege
//    public ResponseDTO<String> delete(@RequestBody @Validated ValidateList<Long> idList) {
//        return visitorService.deleteByIds(idList);
//    }

//    @ApiOperation(value = "批量导出", notes = "@author wuqian")
//    @PostMapping("/orders/export/batch")
//    @NoValidPrivilege
//    public void batchExport(@RequestBody @Validated ValidateList<Long> idList, HttpServletResponse response) {
//        //查询数据
//        List<OrdersExcelVO> ordersList = visitorService.queryBatchExportData(idList);
//        //导出操作
//        ExportParams ex = new ExportParams("批量工单列表", "Sheet1");
//        Workbook workbook = ExcelExportUtil.exportExcel(ex, OrdersExcelVO.class, ordersList);
//        downloadExcel("批量工单列表", workbook, response);
//    }

//    @ApiOperation(value = "导出全部", notes = "@author wuqian")
//    @PostMapping("/orders/export/all")
//    @NoValidPrivilege
//    public void exportAll(@RequestBody @Validated OrdersQueryDTO queryDTO, HttpServletResponse response) {
//        //查询数据
//        List<OrdersExcelVO> ordersList = visitorService.queryAllExportData(queryDTO);
//        //导出操作
//        ExportParams ex = new ExportParams("全部工单列表", "Sheet1");
//        Workbook workbook = ExcelExportUtil.exportExcel(ex, OrdersExcelVO.class, ordersList);
//        downloadExcel("全部工单列表", workbook, response);
//    }

}
